package com.bitdf.txing.users.utils;

import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author Lizhiwei
 * @date 2022/9/15 21:40:34
 * 注释：
 */
public class RedisUtils {
    private static RedisTemplate getRedisTemplate(){
//        System.out.println(stringRedisTemplate);
//        System.out.println(redisUtils.redisTemplate);
//        return redisUtils.getRedisTemplate();
        RedisTemplate redisTemplate = (RedisTemplate) ApplicationContextUtils.getBean("redisTemplate");
//        // 将Key的序列化规则设置为字符串
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // 将Hash中field的序列化规则设置为字符串
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//        redisTemplate.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
//        redisTemplate.setEnableDefaultSerializer(true);
//        redisTemplate.setKeySerializer(new GenericJackson2JsonRedisSerializer());
//        redisTemplate.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
//        redisTemplate.setStringSerializer(new GenericJackson2JsonRedisSerializer());
//        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
//        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        return redisTemplate;
    }

    public static BoundHashOperations<String, Object, Object> getBoundOps(String key, StringRedisTemplate redisTemplate) {
        //绑定key,以后所有redis操作都针对此key
        BoundHashOperations<String, Object, Object> operation = redisTemplate.boundHashOps(key);
        return operation;
    }
}
